<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>显示所有员工</title>
</head>
<body>

<h2>员工列表</h2>
<?php
 // 查询数据库中所有的员工记录
 $conn = mysqli_connect('localhost','root','','toma');
 mysqli_query($conn,'SET NAMES UTF8');
 $sql = 'SELECT eno,ename,salary,borthday,gender,isMarried,deptNo
 FROM emp';
 $result = mysqli_query($conn,$sql);
 // echo var_dump($result);

 // $row = mysqli_fetch_array($result); // MYSQLI_NUM / MYSQLI_ASSOC
 $data = [];
 while ($row = mysqli_fetch_array($result)) {
   $data[] = $row; // 抓取一行记录到二维数组
 }
 // 直接返回json
 $jsonString = json_encode($data,MYSQLI_ASSOC);
 echo $jsonString;
 ?>
 <table border="1" width="500">
   <tr>
     <th>ID</th>
     <th>姓名</th>
     <th>性别</th>
     <th>工资</th>
     <th>生日</th>
     <th>婚否</th>
     <th>所在部门</th>
     <th>操作</th>
   </tr>
 <?php for ($i=0; $i < count($data); $i++) { $row = $data[$i]; ?>
 <tr>
   <td><?php echo $row['eno']; ?></td>
   <td><?php echo $row['ename']; ?></td>
   <td><?php echo $row['salary']; ?></td>
   <td><?php echo $row['borthday']; ?></td>
   <td><?php echo $row['gender']; ?></td>
   <td><?php echo $row['isMarried']?'已婚':'未婚'; ?></td>
   <td><?php echo $row['deptNo']; ?></td>
   <td>
     <a href="1-delemp.do.php?eno=<?php echo $row['eno']; ?>">删除</a>
     <button type="button">修改</button>
   </td>
 </tr>
 <?php } ?>
 </table>
<br>
 <a href="ic.html">返回主菜单</a>


<!-- <table border="1" width="500">
  <tr>
    <th>姓名</th>
    <th>工资</th>
  </tr>
<?php for ($i=0; $i < count($data); $i++) { $row = $data[$i]; ?>
<tr>
  <td><?php echo $row['ename']; ?></td>
  <td><?php echo $row['salary']; ?></td>
</tr>
<?php } ?>
</table> -->

</body>
</html>
